<template>
  <div>
    <van-sticky :offset-top="0">
      <van-nav-bar
        title="品牌列表"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      />
    </van-sticky>

    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div class="item" v-for="(item, index) in list" :key="index">
        <div @click="tobranddetail(item.id)" class="content">
          <img :src="item.app_list_pic_url" alt="" />
          <h3>{{ item.name }}</h3>
        </div>
      </div>
    </van-list>
  </div>
</template>

<script>
import { index, goodsList, detailaction, listaction } from "@/api/home/index";
export default {
  components: {},

  data() {
    return {
      list: [],
      start: 1,
      loading: false,
      finished: false,
      refreshing: false,
    };
  },

  created() {
    listaction({ page: 1 }).then((res) => {
      console.log(res);
      this.list.push(...res.data);
    });
  },

  mounted() {},

  methods: {
    //到品牌直供详细页面
    tobranddetail(id) {
      this.$router.push({
        name: "branddetail",
        params: {
          id: id,
        },
      });
    },
    onClickLeft() {
      this.$router.go(-1);
    },
    // 下滑加载事件
    onLoad() {
      listaction({ page: this.start }).then((res) => {
        console.log(res);
        this.list.push(...res.data);
        this.loading = false;
        if (this.start == res.total) {
          this.finished = true;
        }
        this.start++;
      });
    },
  },

  computed: {},

  watch: {},
};
</script>

<style scoped lang='less'>
.content {
  width: 375px;
  height: 210px;
  position: relative;
  margin-top: 10px;
  img {
    width: 375px;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 2;
  }
  h3 {
    width: 355px;
    height: 30px;
    font-size: 20px;
    line-height: 30px;
    color: white;
    padding: 0 10px;
    z-index: 3;
    position: absolute;
    top: 90px;
  }
}
</style>